﻿<UserControl x:Class="SilverlightLayouts.Layouts.HeaderFreezeLayout"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sl="clr-namespace:SilverlightLayouts.Layouts"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <ScrollViewer x:Name="ScrollLayout"
                  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  HorizontalScrollBarVisibility="Auto">

        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

            <!--Header content control-->
            <ContentControl x:Name="HeaderContainer"
                            Height="{Binding HeaderHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"            
                            Margin="{Binding VerticalOffset, RelativeSource={RelativeSource FindAncestor, AncestorType=ScrollViewer}, Converter={StaticResource ScrollOffsetConverter}}"
                            VerticalAlignment="Top" Canvas.ZIndex="1000">
                
                <ContentControl.Template>
                    <ControlTemplate TargetType="ContentControl">
                        <ContentPresenter
                                        x:Name="HeaderPresenter"
                                        Content="{TemplateBinding Content}"
                                        ContentTemplate="{TemplateBinding ContentTemplate}" />
                    </ControlTemplate>
                </ContentControl.Template>
            </ContentControl>
                
           
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

                <Grid.RowDefinitions>
                    <RowDefinition Height="{Binding HeaderHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Converter={StaticResource GridLengthConverter}}" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                
                <!--Scroll content control-->
                <ContentControl x:Name="ScrollContainer"
                                Grid.Row="1">
                    <ContentControl.Template>
                        <ControlTemplate TargetType="ContentControl">
                            <ContentPresenter
                                    x:Name="ScrollPresenter"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    VerticalAlignment="Stretch"
                                    HorizontalAlignment="Stretch" />
                        </ControlTemplate>
                    </ContentControl.Template>
                </ContentControl>

            </Grid>
        
        </Grid>

    </ScrollViewer>
        
</UserControl>
